import java.util.*;

// 叠盘子
public class StackPlates {
    public static String solution(String plates) {
        // 将输入字符串转换为整数数组
        String[] numbers = plates.split(" ");
        int[] plateArray = new int[numbers.length];
        for (int i = 0; i < numbers.length; i++) {
            plateArray[i] = Integer.parseInt(numbers[i]);
        }

        List<String> result = new ArrayList<>();
        int start = 0;
        int end = 0;

        for (int i = 1; i < plateArray.length; i++) {
            if (plateArray[i] != plateArray[i-1] + 1) {
                if (i - start >= 3) {
                    result.add(formatGroup(plateArray[start], plateArray[i-1]));
                } else {
                    for (int j = start; j < i; j++) {
                        result.add(String.valueOf(plateArray[j]));
                    }
                }
                start = i;
            }
        }

        // 处理最后一组
        end = plateArray.length - 1;
        if (end - start >= 2) {
            result.add(formatGroup(plateArray[start], plateArray[end]));
        } else {
            for (int j = start; j <= end; j++) {
                result.add(String.valueOf(plateArray[j]));
            }
        }

        return String.join(",", result);
    }

    private static String formatGroup(int start, int end) {
        return start == end ? String.valueOf(start) : start + "-" + end;
    }

    public static void main(String[] args) {
        // 测试用例
        System.out.println(solution("-3 -2 -1 2 10 15 16 18 19 20").equals("-3--1,2,10,15,16,18-20"));
        System.out.println(solution("-6 -3 -2 -1 0 1 3 4 5 7 8 9 10 11 14 15 17 18 19 20").equals("-6,-3-1,3-5,7-11,14,15,17-20"));
        System.out.println(solution("1 2 7 8 9 10 11 19").equals("1,2,7-11,19"));
    }
}